package org.liuhy.control
{
	import flash.display.Sprite;
	import flash.geom.Point;
	
	import org.liuhy.line.Arrow;	
	public class UpDownCursor extends Sprite
	{	
		public var radius:int=2;
//        public var fromPoint:Point;
//        public var toPoint:Point;
        //线性的颜色
        public var lineColor:uint=0x00FF00;
        //是否需要画箭头
        public var needArrow:Boolean=true; 
		private function getAngle(fromPoint:Point,toPoint:Point):int
        {
            var  tmpx:int=toPoint.x-fromPoint.x ;
            var tmpy:int=fromPoint.y -toPoint.y ;
            var angle:int= Math.atan2(tmpy,tmpx)*(180/Math.PI);
            return angle;
        }
		
		public function UpDownCursor()
		{
			graphics.lineStyle(1,lineColor);			
			graphics.moveTo(0,-10);			
            graphics.lineTo(0,10);
//            var up:Arrow = new Arrow();
//            up.fromPoint = new Point(0,-5);
//            up.toPoint   =new Point(0,5);
//            up.draw();
			this.graphics.moveTo(0,0);
            this.draw(new Point(0,-10),new Point(0,10));
            this.draw(new Point(0,10),new Point(0,-10));
//            this.addChild(up);
            graphics.moveTo(-10,0);
            graphics.lineTo(10,0);
            this.draw(new Point(-10,0),new Point(10,0));
            this.draw(new Point(10,0),new Point(-10,0));

            super(); 
		}
		public function draw(fromPoint:Point,toPoint:Point):void{
//            this.graphics.clear();
            var angle:int =getAngle(fromPoint,toPoint);
            var centerX:int=toPoint.x-radius * Math.cos(angle *(Math.PI/180)) ;
            var centerY:int=toPoint.y+radius * Math.sin(angle *(Math.PI/180)) ;
            var topX:int=toPoint.x ;
            var topY:int=toPoint.y  ;
            
            var leftX:int=centerX + radius * Math.cos((angle +120) *(Math.PI/180))  ;
            var leftY:int=centerY - radius * Math.sin((angle +120) *(Math.PI/180))  ;
            
            var rightX:int=centerX + radius * Math.cos((angle +240) *(Math.PI/180))  ;
            var rightY:int=centerY - radius * Math.sin((angle +240) *(Math.PI/180))  ;
            
            this.graphics.beginFill(lineColor,1);
            
            this.graphics.lineStyle(1,lineColor,1);
           
            this.graphics.moveTo(topX,topY);
            this.graphics.lineTo(leftX,leftY);
            this.graphics.lineTo(rightX,rightY);
            this.graphics.lineTo(topX,topY);
            
//            this.graphics.endFill();
        }
	}
}